﻿using Common.BaseLibrary.Authorization;
using Common.BaseLibrary.Utils;
using DepartmentWork.Migrator.Data;
using DepartmentWork.Model;
using DepartmentWork.Platform.Controllers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DepartmentWork.Platform.Areas.DepartmentArea.Controllers
{
    public class DeskWorkController : BaseController
    {

        /// <summary>
        /// 科室工作列表
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="info"></param>
        /// <returns></returns>
        public ActionResult DeskWork(string flag = "", string flagInfo = "")
        {
            ViewBag.Flag = flag;
            ViewBag.FlagInfo = flagInfo;
            #region 设置分页

            var pageSizeExecute = this.Request["pageSizeExecute"] == null ? 10 : int.Parse(Request["pageSizeExecute"]);
            var pageIndexExecute = this.Request["pageIndexExecute"] == null ? 1 : int.Parse(Request["pageIndexExecute"]);

            ViewData["pageIndexExecute"] = pageIndexExecute;
            ViewData["pageSizeExecute"] = pageSizeExecute;

            var pageSize = this.Request["pageSizeFinish"] == null ? 10 : int.Parse(Request["pageSizeFinish"]);
            var pageIndex = this.Request["pageIndexFinish"] == null ? 1 : int.Parse(Request["pageIndexFinish"]);

            ViewData["pageIndexFinish"] = pageIndex;
            ViewData["pageSizeFinish"] = pageSize;

            #endregion

            ProjectDeskWorkState model = new ProjectDeskWorkState();//实例化科室工作状态
            model.DeskWorkNo = new DataSet();//未完成0
            model.DeskWorkYes = new DataSet();//完成是1
            IList<PROJECT_DESK_WORK> deskworkNo = new List<PROJECT_DESK_WORK>();//实例化 EF实体类 未完成0
            IList<PROJECT_DESK_WORK> deskworkYes = new List<PROJECT_DESK_WORK>();//实例化 EF实体类 完成1
            List<PROJECT_DESK_WORK> DAI = new List<PROJECT_DESK_WORK>();//实例化 EF实体类 完成1
            List<ProjectDeskWorkViewModel> dai = new List<ProjectDeskWorkViewModel>();
            #region 若不是匿名用户则读取该用户所在的团队空间项目；如果是匿名用户则读取所有团队空间的项目

            if (CurrentUser.UserID.Length != 0)//如果数据库中存在这个用户，说明这个用户是科室人员
            {
                //根据登录ID找到空间ID
                Guid teamSpaceId = userTeamsapceRepository.GetModel(r => r.USER_ID == new Guid(CurrentUser.UserID)).FirstOrDefault().TEAMSPACE_ID;
                deskworkNo = projectdeskworkRepository.GetModel(r => r.TEAMSPACE_ID == teamSpaceId && r.DESKWORK_STATUS == "0").OrderBy(r => r.DESKWORK_DEADINE).ToList();//工作表中，未完成的工作
                deskworkYes = projectdeskworkRepository.GetModel(r => r.TEAMSPACE_ID == teamSpaceId && r.DESKWORK_STATUS == "1").OrderBy(r => r.DESKWORK_CREATETIME).ToList();//工作表中，完成的工作
                Guid myid = new Guid(CurrentUser.UserID);
                var myname = userRepository.Find(r => r.USER_ID == myid).DISPLAY_NAME.ToString();
                ViewBag.myName = myname;//获取到登录人的姓名返回给界面用于锁定发布人

                DAI = projectdeskworkRepository.GetModel(r => r.DESKWORK_PRINCIPAL_ID == myid && r.DESKWORK_STATUS == "0").ToList();//查询登录人带审批工作
                if (DAI.Count > 0)
                {
                    foreach (PROJECT_DESK_WORK daishen in DAI)
                    {
                        ProjectDeskWorkViewModel MODEL = new ProjectDeskWorkViewModel();
                        MODEL.DESKWORK_CREATETIME = daishen.DESKWORK_CREATETIME;
                        MODEL.DESKWORK_DEADINE = daishen.DESKWORK_DEADINE;
                        MODEL.DESKWORK_DESCRIBE = daishen.DESKWORK_DESCRIBE;
                        MODEL.DESKWORK_EDITOR = daishen.DESKWORK_EDITOR;
                        MODEL.DESKWORK_FOUNDER = daishen.DESKWORK_FOUNDER;
                        MODEL.DESKWORK_ID = daishen.DESKWORK_ID;
                        MODEL.DESKWORK_NAME = daishen.DESKWORK_NAME;
                        MODEL.DESKWORK_NO = daishen.DESKWORK_NO;
                        MODEL.DESKWORK_OVERTIME = daishen.DESKWORK_OVERTIME;
                        MODEL.DESKWORK_PRINCIPAL = daishen.DESKWORK_PRINCIPAL;
                        MODEL.DESKWORK_STATUS = daishen.DESKWORK_STATUS;
                        
                        dai.Add(MODEL);
                    }
                }

                #region 获取该团队空间下的全部人员

                List<UserInfoViewModel> userList = new List<UserInfoViewModel>();
                List<USER_TEAMSAPCE> userTeams = userTeamsapceRepository.GetModel(r => r.TEAMSPACE_ID == teamSpaceId).ToList();
                userList.AddRange((from item in userTeams
                                   select new UserInfoViewModel()
                                   {
                                       UserId = item.USER_ID
                                   }).ToList());
                for (int i = 0; i < userList.Count(); i++)
                {
                    var id = userList[i].UserId;
                    userList[i].UserName =
                        userRepository.GetModel(r => r.USER_ID == id).FirstOrDefault().DISPLAY_NAME;
                }
                TempData["UserList"] = userList;

                #endregion

                #region 校验身份
                ViewBag.IsAdmin = false;
                string[] pathArr = Request.Path.Split('/');
                Guid userGuid = new Guid(CurrentUser.UserID);//找到用户登录ID
                USER_INFO user = userRepository.GetModel(r => r.USER_ID == userGuid).FirstOrDefault();//根据用户登录ID 通过员工表 查出此员工信息
                USER_TEAMSAPCE userTeam = userTeamsapceRepository.GetModel(r => r.USER_ID == user.USER_ID).FirstOrDefault();//根据员工的ID 通过团队空间表  查出此人的团队空间信息
                ROLE_INFO role = roleRepository.GetModel(r => r.ROLE_ID == userTeam.ROLE_ID).FirstOrDefault();//根据此人全队空间表信息的团队空间权限ID，查出此人在权限表的信息
                List<MENU_ROLE> menuRole = menuRoleRepository.GetModel(r => r.ROLE_ID == role.ROLE_ID).ToList();//根据此人在权限表的信息中的权限ID，查出此人的菜单表信息
                for (int i = 0; i < menuRole.Count(); i++)
                {
                    int menuId = menuRole[i].MENU_ID;
                    MENU menu = menuRepository.GetModel(r => r.MENU_ID == menuId).FirstOrDefault();//根据菜单Id找此人菜单表的所有信息
                    if (menu.AREA_NAME == pathArr[2] && menu.CONTROLLER_NAME == pathArr[2])
                    {
                        ViewBag.IsAdmin = true;
                        break;
                    }
                }
                #endregion
                #region 校验该登录用户所有负责的项目 返回前台判断是否能在界面进入项目工作
                if (CurrentUser.UserID.Length != 0)
                {
                    //List<ProjectDeskWorkViewModel> aplist = new List<ProjectDeskWorkViewModel>();
                    //Guid userF = new Guid(CurrentUser.UserID);
                    //List<PROJECT_DESK_WORK> developUser = projectdeskworkRepository.GetModel(r => r.DESKWORK_PRINCIPAL_ID == userF).ToList();
                    //if (developUser.Count > 0)
                    //{
                    //    foreach (PROJECT_DESK_WORK ap in developUser)
                    //    {
                    //        ProjectDeskWorkViewModel pm = new ProjectDeskWorkViewModel();
                    //        PROJECT_DESK_WORK app = projectdeskworkRepository.GetModel(r => r.DESKWORK_ID == ap.DESKWORK_ID).FirstOrDefault();
                    //        pm.DESKWORK_ID = app.DESKWORK_ID;
                    //        aplist.Add(pm);
                    //    }
                       
                    //}
                    //ViewBag.currentUser = aplist;
                    ViewBag.currentID = userGuid;
                 
                }

                #endregion

                ViewBag.PAN = true;//用于判断，如果不是匿名用户，显示自己的代办
            }
            else//如果是匿名用户
            {
                deskworkNo = projectdeskworkRepository.GetModel(r => r.DESKWORK_STATUS == "0").OrderBy(r => r.DESKWORK_CREATETIME).ToList();//所有科室未完成的工作
                deskworkYes = projectdeskworkRepository.GetModel(r => r.DESKWORK_STATUS == "1").OrderBy(r => r.DESKWORK_CREATETIME).ToList();//所有科室完成的工作
                ViewBag.NIIsAdmin = false;
            }

            model.DeskWorkNo = DataSetHelp.Instance.ToDataSet(deskworkNo);//将数据库实体类未完成的工作添加到返回给界面的Model中
            model.DeskWorkYes = DataSetHelp.Instance.ToDataSet(deskworkYes); 

            model.DeskWorkNo.Tables[0].Columns.Add("PROJECT_LEADER");//?
            model.DeskWorkYes.Tables[0].Columns.Add("PROJECT_LEADER");//?

            #endregion

            ViewData["totalExecute"] = model.DeskWorkNo.Tables[0].Rows.Count;
            ViewData["totalFinish"] = model.DeskWorkYes.Tables[0].Rows.Count;


            ViewBag.DAI = dai;
            return View(model);//返回给视图
        }



        /// <summary>
        /// 新增科室工作
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult CreateProject(FormCollection collection)
        {

            try
            {
                Guid teamSpaceId = userTeamsapceRepository.GetModel(r => r.USER_ID == new Guid(CurrentUser.UserID)).FirstOrDefault().TEAMSPACE_ID;
                int count = 0;
                List<PROJECT_DESK_WORK> NO = projectdeskworkRepository.GetModel().ToList();
                if (NO == null)
                {
                    count = 1;
                }
                else
                {
                    count = NO.Count + 1;
                }
                #region 获取项目信息数据
                string no = teamspaceRepository.GetModel(p => p.TEAMSPACE_ID == teamSpaceId).FirstOrDefault().TEAMSPACE_NO;
                PROJECT_DESK_WORK work = new PROJECT_DESK_WORK();
                Guid myid = new Guid(collection["select_WorkLeader"]);
                var myname = userRepository.Find(r => r.USER_ID == myid).DISPLAY_NAME.ToString();//要权限
                work.DESKWORK_ID = Guid.NewGuid();
                work.DESKWORK_NAME = collection["tb_WorkName"];
                work.DESKWORK_PRINCIPAL = myname;
                work.DESKWORK_PRINCIPAL_ID = new Guid(collection["select_WorkLeader"]);
                work.DESKWORK_FOUNDER = collection["select_WorkEmp"];
                work.DESKWORK_FOUNDER_ID = new Guid(CurrentUser.UserID);
                work.DESKWORK_STATUS = "0";
                work.DESKWORK_DESCRIBE = collection["tb_Describe"];
                work.DESKWORK_CREATETIME = DateTime.Now;
                work.DESKWORK_OVERTIME = DateTime.Now.AddDays(1);
                work.DESKWORK_NO = "L" + no + DateTime.Now.Year + count.ToString().PadLeft(3, '0');
                work.DESKWORK_DEADINE = Convert.ToDateTime(collection["tb_BTime"]);
                work.DESKWORK_EDITOR = 2;//新建的工作处于驳回状态
                work.TEAMSPACE_ID = teamspaceRepository.GetModel(r => r.TEAMSPACE_NAME == CurrentUser.Department).FirstOrDefault().TEAMSPACE_ID;
                #endregion

                #region 获取人员列表

                //List<PROJECT_DESK_WORK> proUserList = new List<PROJECT_DESK_WORK>();

                //for (int i = 0; i < leadersArr.Length; i++)
                //{
                //    PROJECT_DESK_WORK item = new PROJECT_DESK_WORK();
                //    item.PROJECT_ID = project.PROJECT_DEVELOP_ID;
                //    item.PRO_USER_ID = Guid.NewGuid();
                //    item.USER_ID = new Guid(leadersArr[i]);
                //    item.USER_POSITION = 1;
                //    proUserList.Add(item);
                //    projectDevelopUserRepository.Insert(item);
                //}
                //for (int i = 0; i < proEmpsArr.Length; i++)
                //{
                //    PROJECT_DESK_WORK item = new PROJECT_DESK_WORK();
                //    item.PROJECT_ID = project.PROJECT_DEVELOP_ID;
                //    item.PRO_USER_ID = Guid.NewGuid();
                //    item.USER_ID = new Guid(leadersArr[i]);
                //    item.USER_POSITION = 0;
                //    proUserList.Add(item);
                //    projectDevelopUserRepository.Insert(item);
                //}

                #endregion

                projectdeskworkRepository.Insert(work);
                return RedirectToAction("DeskWork", "DeskWork", new { area = "DepartmentArea", flagInfo = "发布成功！", flag = "True" });
            }
            catch (Exception ex)
            {

                return RedirectToAction("DeskWork", "DeskWork", new { area = "DepartmentArea", flag = "False", flagInfo = "发布失败！" + ex.Message });
            }


        }


        /// <summary>
        /// 编辑科室工作基本信息
        /// </summary>
        public ActionResult CompileDeskWork(string projectId, string flag = "", string flagInfo = "")
        {
            ViewBag.Flag = flag;

            ViewBag.FlagInfo = flagInfo;

            #region 获得工作的基本信息

            Guid workGuid = new Guid(projectId);
            PROJECT_DESK_WORK work = projectdeskworkRepository.GetModel(r => r.DESKWORK_ID == workGuid).FirstOrDefault();//判断传进来的ID是否和当前ID一致

            ProjectDeskWorkViewModel model = new ProjectDeskWorkViewModel()
            {
                DESKWORK_ID = work.DESKWORK_ID,
                DESKWORK_NAME = work.DESKWORK_NAME,
                DESKWORK_PRINCIPAL = work.DESKWORK_PRINCIPAL,
                DESKWORK_DESCRIBE = work.DESKWORK_DESCRIBE,
                DESKWORK_CREATETIME = work.DESKWORK_CREATETIME,
                DESKWORK_FOUNDER = work.DESKWORK_FOUNDER,
                DESKWORK_STATUS = work.DESKWORK_STATUS,
                DESKWORK_OVERTIME = work.DESKWORK_OVERTIME,
                DESKWORK_NO = work.DESKWORK_NO,
                DESKWORK_DEADINE=work.DESKWORK_DEADINE,
                DESKWORK_EDITOR=work.DESKWORK_EDITOR
            };

            if (work.DESKWORK_STATUS == "1")
            {
                model.DESKWORK_STATUS = "工作完成";
            }
            else
            {
                model.DESKWORK_STATUS = "进行中";
            }

            #region 获取该团队空间下的全部人员
            Guid teamSpaceId = userTeamsapceRepository.GetModel(r => r.USER_ID == new Guid(CurrentUser.UserID)).FirstOrDefault().TEAMSPACE_ID;
            List<UserInfoViewModel> userList = new List<UserInfoViewModel>();
            List<USER_TEAMSAPCE> userTeams = userTeamsapceRepository.GetModel(r => r.TEAMSPACE_ID == teamSpaceId).ToList();
            userList.AddRange((from item in userTeams
                               select new UserInfoViewModel()
                               {
                                   UserId = item.USER_ID
                               }).ToList());
            for (int i = 0; i < userList.Count(); i++)
            {
                var id = userList[i].UserId;
                userList[i].UserName =
                    userRepository.GetModel(r => r.USER_ID == id).FirstOrDefault().DISPLAY_NAME;
            }
            TempData["UserList"] = userList;

        
            #endregion
            #endregion

            #region 校验身份
            ViewBag.IsAdmin = false;
            string[] pathArr = Request.Path.Split('/');
            Guid userGuid = new Guid(CurrentUser.UserID);//找到用户登录ID
            USER_INFO user = userRepository.GetModel(r => r.USER_ID == userGuid).FirstOrDefault();//根据用户登录ID 通过员工表 查出此员工信息
            USER_TEAMSAPCE userTeam = userTeamsapceRepository.GetModel(r => r.USER_ID == user.USER_ID).FirstOrDefault();//根据员工的ID 通过团队空间表  查出此人的团队空间信息
            ROLE_INFO role = roleRepository.GetModel(r => r.ROLE_ID == userTeam.ROLE_ID).FirstOrDefault();//根据此人全队空间表信息的团队空间权限ID，查出此人在权限表的信息
            List<MENU_ROLE> menuRole = menuRoleRepository.GetModel(r => r.ROLE_ID == role.ROLE_ID).ToList();//根据此人在权限表的信息中的权限ID，查出此人的菜单表信息
            for (int i = 0; i < menuRole.Count(); i++)
            {
                int menuId = menuRole[i].MENU_ID;
                MENU menu = menuRepository.GetModel(r => r.MENU_ID == menuId).FirstOrDefault();//根据菜单Id找此人菜单表的所有信息
                if (menu.AREA_NAME == pathArr[2] && menu.CONTROLLER_NAME == pathArr[3])
                {
                    ViewBag.IsAdmin = true;
                    break;
                }
            }
            #endregion

            //Guid guid = new Guid(CurrentUser.UserID);//登录人ID判断是否是，决定进入详情界面，是否驳回操作
            //if (guid == work.DESKWORK_AUDITOR_ID)
            //{
            //    ViewBag.GUID = true;
            //}

            List<PROJECT_DESK_WORK_JOBLOGGING> JOBLOGGING = new List<PROJECT_DESK_WORK_JOBLOGGING>();
            List<ProjectDeskWorkJoblogging> joblogging = new List<ProjectDeskWorkJoblogging>();
            JOBLOGGING = projectdeskJoblogging.GetModel(r => r.RECORD_WORK_ID == workGuid&&r.RECORD_CONTENT!="").ToList();

            if (JOBLOGGING.Count > 0)
            {
                foreach (PROJECT_DESK_WORK_JOBLOGGING JOB in JOBLOGGING)
                {
                    var myname = userRepository.Find(r => r.USER_ID ==JOB.RECORD_NAME_ID).DISPLAY_NAME.ToString();
                    ProjectDeskWorkJoblogging job = new ProjectDeskWorkJoblogging();
                    job.RECORD_CONTENT = JOB.RECORD_CONTENT;
                    job.RECORD_ID = JOB.RECORD_ID;
                    job.RECORD_NAME_ID = JOB.RECORD_NAME_ID;
                    job.RECORD_TIME = JOB.RECORD_TIME;
                    job.RECORD_WORK_ID = JOB.RECORD_WORK_ID;
                    job.RECORD_NAME = myname;
                    joblogging.Add(job);
                }

            }
            ViewBag.JOB = joblogging;

            return this.View(model);
        }




        /// <summary>
        /// 提交编辑工作信息
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public ActionResult SubmitCompileWork(FormCollection collection)
        {
            PROJECT_DESK_WORK model = new PROJECT_DESK_WORK();
            model.DESKWORK_ID = new Guid(collection["hid_DESKWORK_ID"]);
            PROJECT_DESK_WORK old = projectdeskworkRepository.GetModel(r => r.DESKWORK_ID == model.DESKWORK_ID).FirstOrDefault();
            Guid myid = new Guid(collection["tb_DESKWORK_PRINCIPAL"]);
            var myname = userRepository.Find(r => r.USER_ID == myid).DISPLAY_NAME.ToString();//要权限
            try
            {
                #region 获取界面数据
                model.DESKWORK_CREATETIME = old.DESKWORK_CREATETIME;
                model.DESKWORK_NAME = collection["tb_DESKWORK_NAME"] == "" ? old.DESKWORK_NAME : collection["tb_DESKWORK_NAME"];
                model.DESKWORK_ID = old.DESKWORK_ID;
                model.DESKWORK_PRINCIPAL_ID = collection["tb_DESKWORK_PRINCIPAL"] == "" ? old.DESKWORK_PRINCIPAL_ID : new Guid(collection["tb_DESKWORK_PRINCIPAL"]);
                model.DESKWORK_PRINCIPAL = myname;
                model.DESKWORK_DESCRIBE = collection["tb_DESKWORK_DESCRIBE"] == "" ? old.DESKWORK_DESCRIBE : collection["tb_DESKWORK_DESCRIBE"];
                model.DESKWORK_STATUS = old.DESKWORK_STATUS;
                model.DESKWORK_OVERTIME = old.DESKWORK_OVERTIME;
                model.DESKWORK_FOUNDER = old.DESKWORK_FOUNDER;
                model.DESKWORK_NO = old.DESKWORK_NO ;
                model.DESKWORK_DEADINE = collection["t_BTime"] == "" ? old.DESKWORK_DEADINE : Convert.ToDateTime(collection["t_BTime"]);
                model.DESKWORK_EDITOR = old.DESKWORK_EDITOR;
                model.DESKWORK_FOUNDER_ID = old.DESKWORK_FOUNDER_ID;
                model.TEAMSPACE_ID = old.TEAMSPACE_ID;
               
                #endregion
                projectdeskworkRepository.Update(model);
                return RedirectToAction("CompileDeskWork", "DeskWork", new { area = "DepartmentArea", projectId = model.DESKWORK_ID, flag = "True", flagInfo = "工作编辑成功！" });

            }
            catch (Exception ex)
            {
                return RedirectToAction("CompileDeskWork", "DeskWork", new { area = "DepartmentArea", projectId = model.DESKWORK_ID, flag = "False", flagInfo = "工作编辑失败！" + ex.Message });
            }




        }




        /// <summary>
        /// 编辑工作状态
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public ActionResult EditWorkStatus(FormCollection collection)
        {
            Guid projectId = new Guid(collection["tb_DESKWORK_ID"]);

            try
            {
                PROJECT_DESK_WORK pro = projectdeskworkRepository.GetModel(r => r.DESKWORK_ID == projectId).FirstOrDefault();

                pro.DESKWORK_STATUS = collection["select_WorkStatus"];
                pro.DESKWORK_OVERTIME = DateTime.Now;
                projectdeskworkRepository.Update(pro);
                return RedirectToAction("CompileDeskWork", "DeskWork", new { area = "DepartmentArea", projectId = projectId, flag = "True", flagInfo = "项目状态编辑完成！" });

            }
            catch (Exception ex)
            {
                return RedirectToAction("CompileDeskWork", "DeskWork", new { aarea = "DepartmentArea", projectId = projectId, info = ex.Message });
            }

        }







        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public ActionResult InserJiLu(FormCollection collection)
        {
            try
            {

                #region 获取项目信息数据

                Guid myid = new Guid(collection["dai_work_idd"]);
                PROJECT_DESK_WORK WORK = projectdeskworkRepository.GetModel(r => r.DESKWORK_ID == myid).FirstOrDefault();


                PROJECT_DESK_WORK work = new PROJECT_DESK_WORK();//要修改的工作表
                work.DESKWORK_ID = WORK.DESKWORK_ID;
                work.DESKWORK_CREATETIME = WORK.DESKWORK_CREATETIME;
                work.DESKWORK_DEADINE = WORK.DESKWORK_DEADINE;
                work.DESKWORK_DESCRIBE = WORK.DESKWORK_DESCRIBE;
                work.DESKWORK_FOUNDER = WORK.DESKWORK_FOUNDER;
                work.DESKWORK_FOUNDER_ID = WORK.DESKWORK_FOUNDER_ID;
                work.DESKWORK_NAME = WORK.DESKWORK_NAME;
                work.DESKWORK_NO = WORK.DESKWORK_NO;
                work.DESKWORK_OVERTIME = WORK.DESKWORK_OVERTIME;
                work.DESKWORK_PRINCIPAL = WORK.DESKWORK_PRINCIPAL;
                work.DESKWORK_PRINCIPAL_ID = WORK.DESKWORK_PRINCIPAL_ID;
                work.DESKWORK_STATUS = WORK.DESKWORK_STATUS;
                work.TEAMSPACE_ID = WORK.TEAMSPACE_ID;
                work.DESKWORK_EDITOR = 1;
              

                PROJECT_DESK_WORK_JOBLOGGING model = new PROJECT_DESK_WORK_JOBLOGGING();//要新增的记录表
                model.RECORD_CONTENT = collection["tb_Describe"];
                model.RECORD_ID = Guid.NewGuid();
                model.RECORD_NAME_ID=WORK.DESKWORK_PRINCIPAL_ID;
                model.RECORD_TIME = DateTime.Now;
                model.RECORD_WORK_ID = WORK.DESKWORK_ID;


                projectdeskworkRepository.Update(work);
                projectdeskJoblogging.Insert(model);

                #endregion


                return RedirectToAction("DeskWork", "DeskWork", new { area = "DepartmentArea", flagInfo = "提交成功！", flag = "True" });
             
            }
            catch (Exception ex)
            {
           
                return RedirectToAction("DeskWork", "DeskWork", new { area = "DepartmentArea", flag = "False", flagInfo = "提交失败！" + ex.Message });
            }






            
        }





        /// <summary>
        /// 驳回
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public ActionResult InserBoHui(FormCollection collection)
        {
            try
            {

                #region 获取项目信息数据

                Guid myid = new Guid(collection["dai_work_idd"]);
                PROJECT_DESK_WORK WORK = projectdeskworkRepository.GetModel(r => r.DESKWORK_ID == myid).FirstOrDefault();


                PROJECT_DESK_WORK work = new PROJECT_DESK_WORK();//要修改的工作表
                work.DESKWORK_ID = WORK.DESKWORK_ID;
                work.DESKWORK_CREATETIME = WORK.DESKWORK_CREATETIME;
                work.DESKWORK_DEADINE = WORK.DESKWORK_DEADINE;
                work.DESKWORK_DESCRIBE = WORK.DESKWORK_DESCRIBE;
                work.DESKWORK_FOUNDER = WORK.DESKWORK_FOUNDER;
                work.DESKWORK_FOUNDER_ID = WORK.DESKWORK_FOUNDER_ID;
                work.DESKWORK_NAME = WORK.DESKWORK_NAME;
                work.DESKWORK_NO = WORK.DESKWORK_NO;
                work.DESKWORK_OVERTIME = WORK.DESKWORK_OVERTIME;
                work.DESKWORK_PRINCIPAL = WORK.DESKWORK_PRINCIPAL;
                work.DESKWORK_PRINCIPAL_ID = WORK.DESKWORK_PRINCIPAL_ID;
                work.DESKWORK_STATUS = WORK.DESKWORK_STATUS;
                work.DESKWORK_EDITOR = 2;
                work.TEAMSPACE_ID = WORK.TEAMSPACE_ID;


                PROJECT_DESK_WORK_JOBLOGGING model = new PROJECT_DESK_WORK_JOBLOGGING();//要新增的记录表
                model.RECORD_CONTENT = collection["tb_Describe"];
                model.RECORD_ID = Guid.NewGuid();
                model.RECORD_NAME_ID = new Guid(CurrentUser.UserID);
                model.RECORD_TIME = DateTime.Now;
                model.RECORD_WORK_ID = WORK.DESKWORK_ID;


                projectdeskworkRepository.Update(work);
                projectdeskJoblogging.Insert(model);

                #endregion



                return RedirectToAction("DeskWork", "DeskWork", new { area = "DepartmentArea", flagInfo = "驳回成功！", flag = "True" });
               
            }
            catch (Exception ex)
            {
                return RedirectToAction("DeskWork", "DeskWork", new { area = "DepartmentArea", flag = "False", flagInfo = "驳回失败！" + ex.Message });
 
            }







        }



        /// <summary>
        /// ajax 获取 
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public JsonResult TiJiao(Guid roleId)
        {


            ProjectDeskWorkViewModel model = new ProjectDeskWorkViewModel();

            PROJECT_DESK_WORK role = projectdeskworkRepository.GetModel(r => r.DESKWORK_ID == roleId).FirstOrDefault();

            model.DESKWORK_ID = role.DESKWORK_ID;
            
            return Json(model);
        }

    }
}
